﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
public partial class backmanage_mailsystem_mail_send : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ForSendMail();
    }
    protected void ForSendMail()
    {
        bool flag = true;
        for (int i = 0; i < 5; i++)
        {
            if (flag)
            {
             flag=SendSMTPMail("smtp.qq.com", "89664557@qq.com", "JHJLOVE@^@145", "449087425@qq.com", ".NET测试发信", "使用.NET测试连续发送邮件<br />，如果您收到说明发送成功！<a href=\"http://www.baidu.com\">百度</a>");
            }
        }
    }
    private bool SendSMTPMail(string stmpStr, string fromStr, string frompaseStr, string toStr, string subStr, string bodyStr)
    {
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(stmpStr);
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential(fromStr, frompaseStr);
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        System.Net.Mail.MailMessage message = new MailMessage();
        message.From=new MailAddress(fromStr);
        message.To.Add(toStr);
        message.Subject = subStr;
        message.Body = bodyStr;
        message.IsBodyHtml = true;
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.IsBodyHtml = true;
        try
        {
            client.Send(message);
            return true;
        }
        catch(Exception ee)
        {
            return false;
        }
    }
}
